package com.fp.m7.manager;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.fp.m7.api.manager.CommentManager;
import com.fp.m7.api.model.Account;
import com.fp.m7.api.model.Comment;
import com.fp.m7.dao.CommentDao;

public class CommentManagerImpl implements CommentManager {

	@Autowired
	private CommentDao commentDao;

	@Override
	public Comment createNew(Account author, String content) {
		com.fp.m7.model.Comment newComment = new com.fp.m7.model.Comment(
				(com.fp.m7.model.Account) author, content);
		return commentDao.persist(newComment);
	}

	@Override
	public Comment findById(Serializable id) {
		return commentDao.getById((Long) id);
	}

	@Override
	public void delete(Comment comment) {
		commentDao.remove((com.fp.m7.model.Comment) comment);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<Comment> findUsersLatestComments(Account user, int maxPerPage,
			int pageNo) {
		List found = commentDao.findUsersLatestComments(
				(com.fp.m7.model.Account) user, maxPerPage, pageNo);
		return found;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<Comment> findUsersCommentsByDate(Account user, Date from,
			Date to) {
		List found = commentDao.findUsersCommentsByDate(
				(com.fp.m7.model.Account) user, from, to);
		return found;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<Comment> findCommentFeedForUser(Account user, int maxPerPage,
			int pageNo) {
		List found = commentDao.findCommentFeedForUser(
				(com.fp.m7.model.Account) user, maxPerPage, pageNo);
		return found;
	}

	@Override
	public int removeUsersComments(Account user) {
		return commentDao.removeUsersComments((com.fp.m7.model.Account) user);
	}

	public void setCommentDao(CommentDao commentDao) {
		this.commentDao = commentDao;
	}

}
